package api

import (
	"api-server/basic/config"
	"api-server/common/model"
	"api-server/handler/request"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func SelectMusic(c *gin.Context) {
	var req request.SelectMusic
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10001,
			"msg":  "验证失败",
			"date": err.Error(),
		})
		return
	}
	var music model.Work
	err := config.DB.Where("music = ?", req.Music).Find(&music).Error
	if err != nil {
		log.Println("选择音乐不存在")
	}
	newMusic := model.Work{
		Music: req.Music,
	}
	config.DB.Create(&newMusic)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "选择成功",
		"date": newMusic,
	})
}
